package com.xiaoming.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaoming.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 测试Controller
 * @author xiaoming
 * @Date 2020/4/25
 * @blame Android Team
 */
@RestController
@Slf4j
public class Controller {

    @Autowired
    private ObjectMapper objectMapper;


    @GetMapping("/jackson")
    public User jackson() throws JsonProcessingException {
        User user = User.builder()
                .name("xiaoming")
                .age(20)
                .address("shanghai")
                .registerTime(new Date())
                .build();

        String value = objectMapper.writeValueAsString(user);
        log.info("user jackson: {}", value);
        return objectMapper.readValue(value, User.class);
    }
}
